<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <!-- 引入 layui.css -->
    <link href="//unpkg.com/layui@2.8.0/dist/css/layui.css" rel="stylesheet">
    <!-- 引入 layui.js -->
    <script src="//unpkg.com/layui@2.8.0/dist/layui.js"></script>

    <style>
        /*#search{*/
            /*margin-top: 30px;*/
            /*margin-left: 1100px;*/
        /*}*/
        #search {
            position: sticky;
            top: 30px;
            right: 310px;
            z-index: 9999;
            margin-top: 35px;
            margin-left: 1150px;
            margin-bottom: -30px;
        }
.layui-form-item{
    margin-top: -5px;
    margin-left: 100px;
}
        #barDemo {
            /*position: fixed;*/
            /*top: 20px;*/
            /*right: 20px;*/
            /*z-index: 9999;*/
        }
    </style>
</head>
<body>

<div class="container">
    <button id="search" class="layui-btn" onclick="keyword()">搜索</button>
</div>
<%--<table class="layui-hide" id="dataTable" lay-filter="dataTable"></table>--%>
<form class="layui-form" action="form.html" id="fm">
    <div class="layui-form-item">
        <div class="layui-inline">
            <div class="layui-inline">
                <label class="layui-form-label">关键词搜索:</label>
                <div class="layui-input-inline">
                    <input type="text" name="productName" lay-verify="required" placeholder="按照 关键词 搜索"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">订单编号:</label>
                <div class="layui-input-inline layui-input-wrap">
                    <input type="text" name="quotationNumber" lay-verify="required" placeholder="按照 订单编号 搜索"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">订单状态:</label>
                <div class="layui-input-inline">
                    <select name="orderStatus" id="orderStatus" lay-verify="required" lay-search>
                        <option value="-1" id="order">所有</option>
                        <option value="1" id="wc">已完成</option>
                        <option value="0" id="ywc">未完成</option>
                    </select>
                </div>
            </div>
            <%--<div class="layui-inline">--%>
            <%--<div class="layui-colla-title">--%>
            <%--<lable>收起搜索</lable>--%>
            <%--</div>--%>
            <%--</div>--%>
            <%--</div>--%>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <div class="layui-collapse">
                <div class="layui-colla-item">
                    <div class="layui-colla-title">
                        <lable>收起搜索</lable>
                    </div>
                    <div class="layui-colla-content">
                        <div class="layui-form-item">
                            <%--<label class="layui-form-label">客户名称:</label>--%>
                            <%--<div class="layui-input-inline">--%>
                                <%--<input type="text" name="username" lay-verify="required" placeholder="按照 客户名称 搜索"--%>
                                       <%--autocomplete="off" class="layui-input">--%>
                            <%--</div>--%>
                            <label class="layui-form-label">款号:</label>
                            <div class="layui-input-inline">
                                <input type="text" name="styleNumber" lay-verify="required" placeholder="按照 款号 搜索"
                                       autocomplete="off" class="layui-input">
                            </div>
                            <%--<label class="layui-form-label">销售员:</label>--%>
                            <%--<div class="layui-input-inline">--%>
                                <%--<input type="text" name="username" lay-verify="required" placeholder="按照 销售员 搜索"--%>
                                       <%--autocomplete="off" class="layui-input">--%>
                            <%--</div>--%>
                        </div>
                        <%--<div class="layui-form-item">--%>
                            <%--<label class="layui-form-label">备注:</label>--%>
                            <%--<div class="layui-input-block">--%>
                                <%--<input type="text" name="orderSrc" lay-verify="required" placeholder="按照 备注 搜索"--%>
                                       <%--autocomplete="off"--%>
                                       <%--class="layui-input">--%>
                            <%--</div>--%>
                        <%--</div>--%>
                        <div class="layui-form-item">
                            <label class="layui-form-label">交易日期:</label>
                            <div class="layui-input-inline">
                                <input type="date" id="startTime" name="startTime" autocomplete="off" class="layui-input" placeholder="开始日期">
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline">
                                <input type="date" id="endTime" name="endTime" autocomplete="off" class="layui-input" placeholder="结束日期">
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">数量:</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="maxQuantity"name="maxQuantity" autocomplete="off" class="layui-input" placeholder="大于此数">
                                </div>
                                <div class="layui-form-mid">-</div>
                                <div class="layui-input-inline">
                                    <input type="text" id="minQuantity"name="minQuantity" autocomplete="off" class="layui-input" placeholder="小于此数">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">金额:</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="orderMoney" name="orderMoneyMin" autocomplete="off" class="layui-input" placeholder="大于此数">
                                </div>

                                <div class="layui-form-mid">-</div>
                                <div class="layui-input-inline">
                                    <input type="text" id="orderMoneyList" name="orderMoneyMax" autocomplete="off" class="layui-input" placeholder="小于此数">
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
    <input type="hidden" id="orderId" name="orderId">
    <input type="hidden" id="auditStatus" name="auditStatus">
</form>


<div class="center-div layui-anim layui-anim-upbit">
    <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="searchForm" onclick="AdvancedSearch()">高级搜索</button>
        <button type="button" class="layui-btn layui-btn-warm">重置</button>
    </div>
</div>
<table class="layui-hide" id="dataTable" lay-filter="dataTable"></table>
<%--<table class="layui-hide" id="dataTable" lay-filter="dataTable"></table>--%>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script type="text/javascript/" id="barDemo">
    <button class="layui-btn layui-btn-danger layui-btn-sm layui-btn-disabled" id="barDemo"  lay-event="deleteProduct" onclick="aa()">审核</button>
</script>
<script type="text/javascript/" id="barDemo1">
    <button class="layui-btn layui-btn-danger layui-btn-sm" id="1barDemo"  lay-event="deleteProduct" onclick="aa()">未审核</button>
</script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script type="text/javascript">
    // layui.use(function () {
    //     var element = layui.element;
    //     var layer = layui.layer;
    //     // 折叠面板点击事件
    //     element.on('collapse(filter-collapse)', function (data) {
    //         console.log(data.show); // 得到当前面板的展开状态，true or false
    //         console.log(data.title); // 得到当前点击面板的标题区域对象
    //         console.log(data.content); // 得到当前点击面板的内容区域对象
    //
    //         // 显示状态，仅用于演示
    //         layer.msg('展开状态：' + data.show);
    //     });
    // });

    layui.use('table', function () {
        var table = layui.table;
        // 创建渲染实例
        table.render({
            elem: '#dataTable',
            height: 600,
            url: 'orderFrom/getOrderColorSizeClient', // 数据接口
            page: true, // 开启分页
            limit: 10,
            limits: [12],
            toolbar: '#toolbarDemo', // 工具栏选择器
            cols: [
                [
                    //{type: 'checkbox', fixed: 'left'},
                    { field: 'orderId', title: '订单ID' },
                    { field: 'styleNumber', title: '款号' },
                    { field: 'measurement', title: '规格' },
                    { field: 'name', title: '尺寸' },
                    { field: 'colorName', title: '颜色' },
                    { field: 'productName', title: '商品名称' },
                    { field: 'quotationNumber', title: '订单编号' },
                    { field: 'productCount', title: '订单的数量' },
                    { field: 'deliveryTime', title: '交期时间' },
                    { field: 'orderMoney', title: '订单金额' },
                    { field: 'deliveryAddress', title: '交货地址'},
                    { field: 'orderStatus', title: '订单状态', templet: function (d) {
                            if (d.orderStatus == "1") {
                                return "已完成";
                            } else if (d.orderStatus =="0") {
                                return "未完成";
                            } else {
                                return '';
                            }
                        }
                    },
                    { field: '', title: '操作', width: 140,templet: function (d) {
                            // alert(d.auditStatus )
                            if (d.auditStatus =="1") {
                                return '<button class="layui-btn layui-btn-danger layui-btn-sm layui-btn-disabled" id="barDemo"  lay-event="deleteProduct">已提交审核</button>\n';
                            } else if (d.auditStatus =="0") {
                                return '<button class="layui-btn layui-btn-danger layui-btn-sm" id="1barDemo"  lay-event="deleteProduct">审核</button>';
                            }
                        }}
                ]
            ]
        });
    });


    layui.use('table', function() {
        var table = layui.table;
        // 监听表格工具栏按钮的点击事件
        table.on('tool(dataTable)', function(obj) {
            var data = obj.data; // 获得当前行数据
            if (obj.event === 'deleteProduct') {
                var orderId = data.orderId; // 提取订单ID
                alert(orderId); // 显示订单ID
                $.ajax({
                    url: 'orderFrom/getModifyOrder',
                    type: 'GET',
                    data: {orderId: orderId},
                    dataType: 'json',
                    contentType: 'application/json;charset=utf-8',
                    success: function(result) {
                        if (result ==1) {
                            // 修改按钮文本为"已提交审核"
                            var btnElem = $(obj.tr).find('.layui-btn');
                            btnElem.text('已提交审核');
                            btnElem.removeClass('layui-btn-danger').addClass('layui-btn-disabled');
                            btnElem.attr('disabled', 'disabled');
                        } else {
                            alert("已审核过了");
                        }
                    },
                    error: function(jqXHR, textStatus, errorThrown) {
                        alert('请求失败，错误信息：' + errorThrown);
                    }
                });

            }

        });
    });
   // RevisionReview()
    function RevisionReview() {
        let orderId = $('[name=orderId]').val();
        // alert(orderId)
        $.ajax({
            "url"            :  "orderFrom/getOrderButton",                      // 要提交的URL路径
            "type"         :  "get",                     // 发送请求的方式
            "data"         : {orderId:orderId},                      // 要发送到服务器的数据
            "dataType" :  "json",                   // 期望接受的数据格式
            //contentType:"application/json;charset=utf-8",
            "success"  :  function(result) {
                var auditStatus = result[0].auditStatus; // 假设服务器返回的审核状态字段为auditStatus
                alert(auditStatus);

                // 根据审核状态更新按钮的文本和样式
                var btnElem = $(obj.tr).find('#scid');
                if (auditStatus =="1") {
                    btnElem.text('已提交审核');
                    btnElem.removeClass('layui-btn-danger').addClass('layui-btn-disabled');
                    btnElem.attr('disabled', 'disabled');
                } else if (auditStatus =="0") {
                    btnElem.text('审核状态');
                    btnElem.removeClass('layui-btn-disabled').addClass('layui-btn-danger');
                    btnElem.removeAttr('disabled');
                }
            },
            "error"       :  function() {           // 请求失败后要执行的代码
                alert("出错了");
            }
        } );

    }
</script>
<script>
    function keyword() {
        let productName = $('[name=productName]').val();
        let quotationNumber = $('[name=quotationNumber]').val();
        let orderStatus = $('[name=orderStatus]').val();
        let styleNumber = $('[name=styleNumber]').val();
        let startTime = $('[name=startTime]').val();
        let endTime = $('[name=endTime]').val();


        //alert(productName);
        var requestData = {
            productName: productName,
            quotationNumber:quotationNumber,
            orderStatus:orderStatus,
            styleNumber:styleNumber,
        };
        $.ajax({
            url: 'orderFrom/getOrderListView',
            type: 'post',
            data: requestData,
            dataType: 'json',
            success: function (result) {
                // 清空原有表格内容
                $('#dataTable').empty();

                layui.use('table', function () {
                    var table = layui.table;
                    table.render({
                        elem: '#dataTable',
                        data: result,
                        cols: [
                            [
                                //{type: 'checkbox', fixed: 'left'},
                                {field: 'orderId', title: '订单ID'},
                                {field: 'styleNumber', title: '款号'},
                                {field: 'measurement', title: '规格'},
                                {field: 'name', title: '尺寸'},
                                {field: 'colorName', title: '颜色'},
                                {field: 'productName', title: '商品名称'},
                                {field: 'quotationNumber', title: '订单编号'},
                                {field: 'productCount', title: '订单的数量'},
                                {field: 'deliveryTime', title: '交期时间'},
                                {field: 'orderMoney', title: '订单金额'},
                                {field: 'deliveryAddress', title: '交货地址'},
                                {field: 'orderStatus', title: '订单状态', templet:function (b) {
                                        if(b.orderStatus=="1"){
                                            return "已完成";
                                        }else if(b.orderStatus=="0"){
                                            return "未完成";
                                        }
                                    }},
                                { field: '', title: '操作', width: 140,templet: function (d) {
                                        // alert(d.auditStatus )
                                        if (d.auditStatus =="1") {
                                            return '<button class="layui-btn layui-btn-danger layui-btn-sm layui-btn-disabled" id="barDemo"  lay-event="deleteProduct">已提交审核</button>\n';
                                        } else if (d.auditStatus =="0") {
                                            return '<button class="layui-btn layui-btn-danger layui-btn-sm" id="1barDemo"  lay-event="deleteProduct">审核</button>';
                                        }
                                    }}
                            ]
                        ]
                    });
                });

            },error:function () {
                alert("查询出错")
            }
        });
    }
    function AdvancedSearch() {
        let maxQuantity = $('[name=maxQuantity]').val();
        let minQuantity= $('[name=minQuantity]').val();
        let orderMoneyMin = $('[name=orderMoneyMin]').val();
        let orderMoneyMax = $('[name=orderMoneyMax]').val();
        // 检查是否至少填写了一个字段
        if (!(maxQuantity || minQuantity || orderMoneyMin || orderMoneyMax)) {
            alert('请至少填写一个输入框或一个下拉框');
            return;
        }
        var requestData = {
            maxQuantity: maxQuantity,
            minQuantity: minQuantity,
            orderMoneyMin: orderMoneyMin,
            orderMoneyMax: orderMoneyMax
        }
        $.ajax({
            url: 'orderFrom/getOrderListView',
            type: 'post',
            data: requestData,
            dataType: 'json',
            success: function (result) {
                //alert(1111111);
                // 清空原有结果显示
                //dataTable
                // $('#dataTable').empty();

                // 清空原有表格内容
                $('#dataTable').empty();

                layui.use('table', function () {
                    var table = layui.table;
                    table.render({
                        elem: '#dataTable',
                        data: result,
                        cols: [
                            [
                                //{type: 'checkbox', fixed: 'left'},
                                {field: 'orderId', title: '订单ID'},
                                {field: 'styleNumber', title: '款号'},
                                {field: 'measurement', title: '规格'},
                                {field: 'name', title: '尺寸'},
                                {field: 'colorName', title: '颜色'},
                                {field: 'productName', title: '商品名称'},
                                {field: 'quotationNumber', title: '订单编号'},
                                {field: 'productCount', title: '订单的数量'},
                                {field: 'deliveryTime', title: '交期时间'},
                                {field: 'orderMoney', title: '订单金额'},
                                {field: 'deliveryAddress', title: '交货地址'},
                                {field: 'orderStatus', title: '订单状态', templet:function (b) {
                                        if(b.orderStatus=="1"){
                                            return "已完成";
                                        }else if(b.orderStatus=="0"){
                                            return "未完成";
                                        }
                                    }},
                                { field: '', title: '操作', width: 140,templet: function (d) {
                                        // alert(d.auditStatus )
                                        if (d.auditStatus =="1") {
                                            return '<button class="layui-btn layui-btn-danger layui-btn-sm layui-btn-disabled" id="barDemo"  lay-event="deleteProduct">已提交审核</button>\n';
                                        } else if (d.auditStatus =="0") {
                                            return '<button class="layui-btn layui-btn-danger layui-btn-sm" id="1barDemo"  lay-event="deleteProduct">审核</button>';
                                        }
                                    }}
                            ]
                        ]
                    });
                });

            },error:function () {
                alert("查询出错")
            }
        });
    }
</script>

</body>
</html>
